package models

/*import (
	"gorm.io/gorm"
)*/
//出口贸易滞港
type In2 struct {
	Inmon2  string `gorm:"column:inmon2"`
	Inday2  string `gorm:"column:inday2"`
	Inno2   string `gorm:"column:inno2"`
	Ton2    string `gorm:"column:ton2"`
	Company string `gorm:"column:company"`
	Object1 string `gorm:"column:object1"`
}

func GetAllIn2(In2Param map[string]interface{}) (error, []In2, int64) {
	var in2Data []In2
	page := In2Param["page"].(int)
	pageSize := In2Param["limit"].(int)
	searchText := In2Param["searchText"].(string)
	var total int64
	err := db.Table("in2").Where("inno2 like ?", "%"+searchText+"%").Order("inno2 ASC").Count(&total).Find(&in2Data).Offset((page - 1) * pageSize).Limit(pageSize).Error
	return err, in2Data, total
}

func AddIn2(in2data In2) (error, In2) {
	err := db.Table("in2").Select("inmon2", "inday2", "inno2", "ton2", "company", "object1").Create(&in2data).Error
	return err, in2data
}

func UpdateIn2(inno2 string, in2data In2) (error, In2) {
	err := db.Table("in2").Where("inno2 = ?", in2data.Inno2).Updates(&in2data).Error
	return err, in2data
}

func DeleteIn2(inno2 string) (error, In2) {
	var in2data In2
	in2data.Inno2 = inno2
	err := db.Table("in2").Where("inno2 = ?", inno2).Find(&in2data).Delete(In2{}).Error
	return err, in2data
}
